<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>

<head>
    <title>全部动漫 - AGE动漫</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <link type="text/css" rel="stylesheet" href="${pageContext.request.contextPath}/static/css/common.css">
    <link type="text/css" rel="stylesheet" href="${pageContext.request.contextPath}/static/css/bootstrap.min.css">
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/js/jquery-1.11.0.min.js"></script>
    <script>
        $(document).ready(function () {
            limitAddClick();

            $.get("${pageContext.request.contextPath}/directory/initYear",function (data) {
                let context = ``;
                for (let i = 0; i < data.data.length; i++) {
                    context = context + `
                        <a>` + data.data[i] + `</a>
                    `;
                }
                $("#year").after(context);
            })

            $.get("${pageContext.request.contextPath}/directory/init",function (data) {
                let context = ``;
                for (let i = 0; i < data.data.length; i++) {
                    context = context + `
                        <a id="` + data.data[i].cid + `">` + data.data[i].cname + `</a>
                    `;
                }
                $("#category").after(context);
                
                $(".search_ul a").click(function () {
                    $(this).parent().children().each(function () {
                        $(this).removeClass("search_active");
                    })
                    $(this).addClass("search_active");
                    let cid = $("#category_nav>.search_active").attr("id");
                    if (cid == "category") {
                        cid = "";
                    }
                    let year = $("#year_nav>.search_active").html();
                    let quarter = $("#quarter_nav>.search_active").html();
                    switch (quarter) {
                        case "第一季度":
                            quarter = 1;
                            break;
                        case "第二季度":
                            quarter = 2;
                            break;
                        case "第三季度":
                            quarter = 3;
                            break;
                        case "第四季度":
                            quarter = 4;
                            break;
                        default:
                            break;
                    }
                    let state = $("#state_nav>.search_active").html();
                    let sort = $("#sort_nav>.search_active").html();
                    $.ajax({
                        url:"${pageContext.request.contextPath}/animation/search",
                        type:"post",
                        data:{"aname":"${sessionScope.search.aname}","cid":cid,"year":year,"quarter":quarter,"state":state,"sort":sort},
                        dataType:"json",
                        success:function (data) {
                            let searchLimit = ``;
                            let searchContext = ``;
                            if (data.flag) {
                                let limit = data.data.limit;
                                data = data.data.list;
                                for (let i = 0; i < data.length; i++) {
                                    searchContext = searchContext + `
                                <a href="${pageContext.request.contextPath}/animation/show_detailed?aid=` + data[i].animationSimple.aid + `" class="cell_poster">
                                    <img referrerpolicy="no-referrer" width="150px" height="208px" src="${pageContext.request.contextPath}` + data[i].animationSimple.cover_img + `">
                                    <span class="newname">` + data[i].animationSimple.score + `</span>
                                </a>
                                <div class="cell_imform">
                                <div>
                                    <a href="${pageContext.request.contextPath}/animation/show_detailed?aid=` + data[i].animationSimple.aid + `" class="cell_imform_name">` + data[i].animationSimple.aname + `</a>
                                </div>
                                <div class="cell_imform_kvs">
                                    <div class="cell_imform_kv">
                                        <span class="cell_imform_tag">动画种类：</span>
                                        <span class="cell_imform_value">TV</span></div>
                                    <div class="cell_imform_kv">
                                        <span class="cell_imform_tag">原版名称：</span>
                                        <span class="cell_imform_value">` + data[i].animationSimple.aname_jp + `</span></div>
                                    <div class="cell_imform_kv">
                                        <span class="cell_imform_tag">评分：</span>
                                        <span class="cell_imform_value">` + data[i].animationSimple.score + `</span></div>
                                    <br>
                                    <div class="cell_imform_kv">
                                        <span class="cell_imform_tag">首播时间：</span>
                                        <span class="cell_imform_value">` + data[i].animationSimple.create_time + `</span></div>
                                    <div class="cell_imform_kv">
                                        <span class="cell_imform_tag">播放状态：</span>
                                        <span class="cell_imform_value">评分：` + data[i].animationSimple.state + `</span></div>
                                    <div class="cell_imform_kv">
                                        <span class="cell_imform_tag">原作：</span>
                                        <span class="cell_imform_value">` + data[i].animationSimple.author + `</span></div>
                                    <br>
                                    <div class="cell_imform_kv">
                                        <span class="cell_imform_tag">剧情类型：</span>
                                        <span class="cell_imform_value">` + data[i].category.cname + `</span></div>
                                    <div class="cell_imform_kv">
                                        <span class="cell_imform_tag">制作公司：</span>
                                        <span class="cell_imform_value">` + data[i].animationSimple.production_company + `</span></div>
                                    <div class="cell_imform_kv cell_imform_kv_desc">
                                        <span class="cell_imform_tag">简介：</span>
                                        <div class="cell_imform_desc">` + data[i].animationSimple.simple_introduce + `</div>
                                    </div>
                                </div>
                                <div class="cell_imform_btns">
                                    <a class="nbutton2 cell_res_button" href="${pageContext.request.contextPath}/animation/show_detailed?aid=` + data[i].animationSimple.aid + `">资源详情</a>
                                    </div>
                                </div>
                            `;
                                }

                                if (limit.currentPage == 1) {
                                    searchLimit = searchLimit + `<li class="disabled"><a>上一页</a></li>`;
                                } else {
                                    searchLimit = searchLimit + `<li><a>上一页</a></li>`;
                                }
                                for (let i = 0; i < limit.pages.length; i++) {
                                    if (limit.pages[i] == limit.currentPage) {
                                        searchLimit = searchLimit + `
                                        <li class="active"><a>` + limit.pages[i] + `</a></li>
                                    `;
                                    } else {
                                        searchLimit = searchLimit + `
                                        <li><a>` + limit.pages[i] + `</a></li>
                                    `;
                                    }
                                }
                                if (limit.currentPage == limit.maxPage) {
                                    searchLimit = searchLimit + `<li class="disabled"><a>下一页</a></li>`;
                                } else {
                                    searchLimit = searchLimit + `<li><a>下一页</a></li>`;
                                }
                                searchLimit = searchLimit + `<p>共<span id="total">` + limit.total + `</span>条记录</p>`;
                            } else {
                                searchContext = searchContext + data.errorMsg;
                                searchLimit = "";
                            }
                            $(".blockdiff").html(searchContext);
                            $("#RecentlyLimit").html(searchLimit);
                            limitAddClick();
                        }
                    })
                })
            },"json")
        })

        function limitAddClick() {
            $("#RecentlyLimit>li").click(function () {
                if (!($(this).hasClass("disabled") || $(this).hasClass("active"))) {
                    let total = Number($("#total").html());
                    let num = ${requestScope.limit.num};
                    let currentPage = $(this).children().html();
                    if (currentPage == "上一页") {
                        $("#RecentlyLimit").children().each(function () {
                            if ($(this).hasClass("active")) {
                                currentPage = -1 + Number($(this).children().html());
                            }
                        })
                    } else if (currentPage == "下一页") {
                        $("#RecentlyLimit").children().each(function () {
                            if ($(this).hasClass("active")) {
                                currentPage = 1 + Number($(this).children().html());
                            }
                        })
                    }
                    flashLimit(total, num, currentPage);
                }
            })
        }
        
        function flashLimit(total, num, currentPage) {
            $.ajax({
                url:"${pageContext.request.contextPath}/animation/searchJump",
                type:"post",
                data:{"total":total,"num":num,"currentPage":currentPage},
                dataType:"json",
                success:function (data) {
                    let searchLimit = ``;
                    let searchContext = ``;
                    if (data.flag) {
                        let limit = data.data.limit;
                        data = data.data.list;
                        for (let i = 0; i < data.length; i++) {
                            searchContext = searchContext + `
                                <a href="${pageContext.request.contextPath}/animation/show_detailed?aid=` + data[i].animationSimple.aid + `" class="cell_poster">
                                    <img referrerpolicy="no-referrer" width="150px" height="208px" src="${pageContext.request.contextPath}` + data[i].animationSimple.cover_img + `">
                                    <span class="newname">` + data[i].animationSimple.score + `</span>
                                </a>
                                <div class="cell_imform">
                                <div>
                                    <a href="${pageContext.request.contextPath}/animation/show_detailed?aid=` + data[i].animationSimple.aid + `" class="cell_imform_name">` + data[i].animationSimple.aname + `</a>
                                </div>
                                <div class="cell_imform_kvs">
                                    <div class="cell_imform_kv">
                                        <span class="cell_imform_tag">动画种类：</span>
                                        <span class="cell_imform_value">TV</span></div>
                                    <div class="cell_imform_kv">
                                        <span class="cell_imform_tag">原版名称：</span>
                                        <span class="cell_imform_value">` + data[i].animationSimple.aname_jp + `</span></div>
                                    <div class="cell_imform_kv">
                                        <span class="cell_imform_tag">评分：</span>
                                        <span class="cell_imform_value">` + data[i].animationSimple.score + `</span></div>
                                    <br>
                                    <div class="cell_imform_kv">
                                        <span class="cell_imform_tag">首播时间：</span>
                                        <span class="cell_imform_value">` + data[i].animationSimple.create_time + `</span></div>
                                    <div class="cell_imform_kv">
                                        <span class="cell_imform_tag">播放状态：</span>
                                        <span class="cell_imform_value">评分：` + data[i].animationSimple.state + `</span></div>
                                    <div class="cell_imform_kv">
                                        <span class="cell_imform_tag">原作：</span>
                                        <span class="cell_imform_value">` + data[i].animationSimple.author + `</span></div>
                                    <br>
                                    <div class="cell_imform_kv">
                                        <span class="cell_imform_tag">剧情类型：</span>
                                        <span class="cell_imform_value">` + data[i].category.cname + `</span></div>
                                    <div class="cell_imform_kv">
                                        <span class="cell_imform_tag">制作公司：</span>
                                        <span class="cell_imform_value">` + data[i].animationSimple.production_company + `</span></div>
                                    <div class="cell_imform_kv cell_imform_kv_desc">
                                        <span class="cell_imform_tag">简介：</span>
                                        <div class="cell_imform_desc">` + data[i].animationSimple.simple_introduce + `</div>
                                    </div>
                                </div>
                                <div class="cell_imform_btns">
                                    <a class="nbutton2 cell_res_button" href="${pageContext.request.contextPath}/animation/show_detailed?aid=` + data[i].animationSimple.aid + `">资源详情</a>
                                    </div>
                                </div>
                            `;
                        }

                        if (limit.currentPage == 1) {
                            searchLimit = searchLimit + `<li class="disabled"><a>上一页</a></li>`;
                        } else {
                            searchLimit = searchLimit + `<li><a>上一页</a></li>`;
                        }
                        for (let i = 0; i < limit.pages.length; i++) {
                            if (limit.pages[i] == limit.currentPage) {
                                searchLimit = searchLimit + `
                                        <li class="active"><a>` + limit.pages[i] + `</a></li>
                                    `;
                            } else {
                                searchLimit = searchLimit + `
                                        <li><a>` + limit.pages[i] + `</a></li>
                                    `;
                            }
                        }
                        if (limit.currentPage == limit.maxPage) {
                            searchLimit = searchLimit + `<li class="disabled"><a>下一页</a></li>`;
                        } else {
                            searchLimit = searchLimit + `<li><a>下一页</a></li>`;
                        }
                        searchLimit = searchLimit + `<p>共<span id="total">` + limit.total + `</span>条记录</p>`;
                    } else {
                        searchContext = searchContext + data.errorMsg;
                        searchLimit = "";
                    }
                    $(".blockdiff").html(searchContext);
                    $("#RecentlyLimit").html(searchLimit);
                    limitAddClick();
                }
            })
        }
    </script>
    <style>
        .search_ul>li{
            font-size: 20px;

        }

        .search_active{
            background-color: #f87d67;
            border-radius: 5px;
        }

        .search_ul>li>a{
            font-size: 15px;
            color: #777575;
            margin-left: 20px;
        }

        #RecentlyLimit>p{
            font-size: 20px;
            display: inline;
            margin-left: 10px;
            color: #f66e45
        }

        #RecentlyLimit>p>span{
            color: #f66e45
        }
    </style>

</head>

<body>
<c:import url="../user_view/component/header.jsp"></c:import>
<div id="root">
    <div id="container">
        <div class="baseblock">
            <div class="blockcontent">

                <!-- 目录 -->
                <ul class="search_ul" id="search-list">
                    <li id="category_nav">
                        类型<a class="search_active" id="category">全部</a>
                    </li><br>
                    <li id="year_nav">
                        年份<a class="search_active" id="year">全部</a>
                    </li><br>
                    <li id="quarter_nav">
                        季度<a class="search_active">全部</a><a>第一季度</a><a>第二季度</a><a>第三季度</a><a>第四季度</a>
                    </li><br>
                    <li id="state_nav">
                        状态<a class="search_active">全部</a><a>已完结</a><a>连载中</a><a>即将播出</a>
                    </li><br>
                    <li id="sort_nav">
                        排序<a class="search_active">全部</a><a>更新时间</a><a>热度</a><a>评分</a>
                    </li>
                </ul>
            </div>
        </div>
        <div class="baseblock">
            <div class="blockcontent1">
                <div class="cell blockdiff">
                    <c:forEach items="${requestScope.allAnimationSimple}" var="simple">
                        <a href="${pageContext.request.contextPath}/animation/show_detailed?aid=${simple.animationSimple.aid}" class="cell_poster">
                            <img referrerpolicy="no-referrer" width="150px" height="208px" src="${pageContext.request.contextPath}${simple.animationSimple.cover_img}" alt="${simple.animationSimple.aname}">
                            <span class="newname">${simple.animationSimple.score}</span>
                        </a>
                        <div class="cell_imform">
                            <div>
                                <a href="${pageContext.request.contextPath}/animation/show_detailed?aid=${simple.animationSimple.aid}" class="cell_imform_name">${simple.animationSimple.aname}</a>
                            </div>
                            <div class="cell_imform_kvs">
                                <div class="cell_imform_kv">
                                    <span class="cell_imform_tag">动画种类：</span>
                                    <span class="cell_imform_value">TV</span>
                                </div>
                                <div class="cell_imform_kv">
                                    <span class="cell_imform_tag">原版名称：</span>
                                    <span class="cell_imform_value">${simple.animationSimple.aname_jp}</span>
                                </div>
                                <div class="cell_imform_kv">
                                    <span class="cell_imform_tag">评分：</span>
                                    <span class="cell_imform_value">${simple.animationSimple.score}</span>
                                </div>
                                <br>
                                <div class="cell_imform_kv">
                                    <span class="cell_imform_tag">首播时间：</span>
                                    <span class="cell_imform_value">${simple.animationSimple.create_time}</span>
                                </div>
                                <div class="cell_imform_kv">
                                    <span class="cell_imform_tag">播放状态：</span>
                                    <span class="cell_imform_value">${simple.animationSimple.state}</span>
                                </div>
                                <div class="cell_imform_kv">
                                    <span class="cell_imform_tag">原作：</span>
                                    <span class="cell_imform_value">${simple.animationSimple.author}</span>
                                </div>
                                <br>
                                <div class="cell_imform_kv">
                                    <span class="cell_imform_tag">剧情类型：</span>
                                    <span class="cell_imform_value">${simple.category.cname}</span>
                                </div>
                                <div class="cell_imform_kv">
                                    <span class="cell_imform_tag">制作公司：</span>
                                    <span class="cell_imform_value">${simple.animationSimple.production_company}</span>
                                </div>
                                <div class="cell_imform_kv cell_imform_kv_desc">
                                    <span class="cell_imform_tag">简介：</span>
                                    <div class="cell_imform_desc">${simple.animationSimple.simple_introduce}</div>
                                </div>
                            </div>
                            <div class="cell_imform_btns">
                                <a class="nbutton2 cell_res_button" href="${pageContext.request.contextPath}/animation/show_detailed?aid=${simple.animationSimple.aid}">资源详情</a>
                            </div>
                        </div>
                    </c:forEach>
                </div>
                <ul class="pagination" id="RecentlyLimit">
                    <li class="${requestScope.limit.hasPre() ? "" : "disabled"}"><a>上一页</a></li>
                    <c:forEach items="${requestScope.limit.pages}" var="item">
                        <li class="${requestScope.limit.currentPage == item ? "active" : ""}"><a>${item}</a></li>
                    </c:forEach>
                    <li class="${requestScope.limit.hasNext() ? "" : "disabled"}"><a>下一页</a></li>
                    <p>共<span id="total">${requestScope.limit.total}</span>条记录</p>
                </ul>
            </div>
        </div>
    </div>
</div>
</body>

</html>
